﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Linq;

namespace 工作流XMLDomain修改工具.Codes
{
    public class DbServer
    {
        private string address;
        private string user;
        private string password;
        private string dbname;
        private string connStr = "";

        public DbServer(string address, string user, string password, string dbname)
        {
            this.address = address;
            this.user = user;
            this.password = password;
            this.dbname = dbname;
            connStr = string.Format(@"Data Source={0};Initial Catalog={3};User ID={1};Password={2};",
                address, user, password, dbname);
        }

        public bool TestConnection()
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    conn.Open();
                }
                return true;
            }
            catch (Exception) { return false; }
        }

        /// <summary>
        /// 获取数据库链接
        /// </summary>
        /// <returns></returns>
        public SqlConnection GetConnection()
        {
            return new SqlConnection(connStr);
        }
    }
}